package org.supda.system.controller.log;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import org.supda.system.controller.common.BaseController;
import org.supda.system.entity.TLog;
import org.supda.system.service.TLogService;
import org.supda.system.util.DataTablePageUtil;

@Controller
@RequestMapping("/log")
public class LogController extends BaseController{

	@Inject private TLogService tLogService;
	
	//加载列表 /log.shtml
	@RequestMapping(value={"","/"},method=RequestMethod.GET, produces="text/html;charset=utf-8")
	public String listUI(HttpServletRequest request, Model model){
		model.addAttribute("menuId",getOID());
		return BASE_VIEW_PACKAGE+"log/log";
	}
	
	//查询 /log/search.shtml
	@RequestMapping(value="/search",method=RequestMethod.POST, produces="text/html;charset=utf-8")
	public @ResponseBody DataTablePageUtil<TLog> search(WebRequest request, Model model){
		DataTablePageUtil<TLog> dtp = new DataTablePageUtil<TLog>(request); 
    	//开启Or查询
		tLogService.listByDataTable(dtp);
    	return dtp; 
	}
	
	//删除 /log/del.shtml
	@RequestMapping(value="/del", method=RequestMethod.POST, produces="text/html;charset=utf-8")
	public @ResponseBody String del(HttpServletRequest request,
			Long[] id){
		
		try{
			tLogService.delLogs(id);
			return RESPONSE_SUCCESS;
		}catch(Exception e){
			return RESPONSE_FAIL;
		}
	}
	
}
